package com.whfc.ms.api.fse.controller;

import com.whfc.common.base.BaseController;
import com.whfc.common.result.PageData;
import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.common.util.SessionAttr;
import com.whfc.fse.dto.FseLiftRecordCountDTO;
import com.whfc.fse.dto.FseLiftRecordDTO;
import com.whfc.fuum.entity.SysUser;
import com.whfc.ms.api.fse.service.MsFseLiftRecordService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @author : qzexing
 * @version : 1.0
 * @date : 2020-07-18 10:51
 */
@RequiresPermissions("fse/lift")
@RestController
@RequestMapping("/ms/api/lift/record")
public class FseLiftRecordController extends BaseController {

    @Autowired
    private MsFseLiftRecordService msFseLiftRecordService;

    @GetMapping("/list")
    public Result list(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                       @RequestParam("deptId") Integer deptId,
                       @RequestParam("pageNum") Integer pageNum,
                       @RequestParam("pageSize") Integer pageSize,
                       @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @RequestParam("startTime") Date startTime,
                       @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @RequestParam("endTime") Date endTime,
                       @RequestParam(value = "keyword", required = false) String keyword) {
        logger.info("升级机记录列表,loginer:{},deptId:{},pageNum:{},pageSize:{},startTime:{},endTime:{},keyword:{}",
                user.getUsername(), deptId, pageNum, pageSize, startTime, endTime, keyword);
        PageData<FseLiftRecordDTO> pageData = msFseLiftRecordService.list(deptId, pageNum, pageSize, startTime, endTime, keyword);
        return ResultUtil.success(pageData);
    }

    @GetMapping("/count")
    public Result recordCount(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                              @RequestParam("liftId") Integer liftId,
                              @RequestParam("startTime") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date startTime,
                              @RequestParam("endTime") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endTime) {
        logger.info("升降纪录统计,loginer:{},liftId:{},startTime:{},endTime:{}", user.getUsername(), liftId, startTime, endTime);
        FseLiftRecordCountDTO fseLiftRecordCountDTO = msFseLiftRecordService.recordCount(liftId, startTime, endTime);
        return ResultUtil.success(fseLiftRecordCountDTO);
    }

}
